package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.ShelvesonMapper;
import com.zld.smarket.dto.GoodsList;
import com.zld.smarket.dto.OnshelvesList;
import com.zld.smarket.dto.ShelvesonList;
import com.zld.smarket.pojo.Shelveson;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.ShelvesonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShelvesonServiceImpl implements ShelvesonService {

    @Autowired
    private ShelvesonMapper shelvesonMapper;
    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<ShelvesonList> onshelvesLists = shelvesonMapper.selectAllAndPage(page,limit);
        Long count = shelvesonMapper.countShelveson();
        return new ResponseData(onshelvesLists,count);
    }

    @Override
    public Long selectbyno(Long i) {
        return shelvesonMapper.countShelvesonbyno(i);
    }

    @Override
    public Integer setShelveson(Shelveson shelveson) {
        int j=0;
        j=shelvesonMapper.insert(shelveson);
        return j;
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<ShelvesonList> shelvesonLists =  shelvesonMapper.search(s,page,limit);
        Long count = Long.valueOf(shelvesonLists.size());
        return new ResponseData(shelvesonLists,count);
    }

    @Override
    public Long weekshelveson() {
        return shelvesonMapper.weekshelveson();
    }
}
